package com.atjava.jcrt.utility;

import java.util.ArrayList;
import java.util.List;
/**
 * @author biggie
 */
public class Page {
	
    

	private int curPage=1;

	private int selectNum=20;

	private int num;

	private int pageNum;

	private List list=null;

	private List curList=null;
    /**
     * @return Returns the curPage.
     */
    public int getCurPage() {
        return curPage;
    }

	private int showPage=10;

	private String submitName=null;

	private String formName;

	public Page(List list,int curPage,int selectNum){
		this.list=list;
		this.curPage = curPage;
		this.selectNum=selectNum;
		this.num = list.size();
		this.compute();
	}
	
	public Page(List list,int curPage){
		this.list=list;
		this.curPage = curPage;
		this.num = list.size();
		this.compute();
	}

	private void compute(){
		curList=new ArrayList();
		int start=curPage*selectNum-selectNum;
		int page=curPage*selectNum;
		int end=list.size();
		if(start<end){
			if(end>=page){
				end=page;
			}
		}
		if(start>end){
			start=0;
			end=0;
		}
		for(int i=start;i<end;i++){
			curList.add(list.get(i));
		}
		this.setCurList(curList);
	}

	public int getNum() {		
		return num;
	}

	public int getPageNum() {
		pageNum=(num+selectNum-1)/selectNum;
		if(num==0){
			pageNum=1;
		}
		return pageNum;
	}

	public int getPrePage(){
		int prePage=curPage-1;
		if(prePage<=0){
			prePage=1;
		}
		return prePage;
	}

	public int getNextPage(){
		int nextPage=curPage+1;
		if(nextPage>getPageNum()){
			nextPage=getPageNum();
		}
		return nextPage;
	}


	public int getFirstPage(){
		return 1;
	}

	public int getLastPage(){
		return getPageNum();
	}

    public int getSelectNum() {
        return selectNum;
    }

    public List getCurList() {
        return curList;
    }

    public void setCurList(List curList) {
        this.curList = curList;
    }
}
